import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBEngineer/YBBaseRouter/YBApplication.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBColor/YBColor.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBImageStyle/YBImageStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBTextStyle/YBTextStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/yb_chinese_text/yb_chinese_text.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBJsonToModel/YBWorkTaiModel/YBWorkTaiBaseYiJiModel.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBWorkTaiModule/YBZhuanShuYingYongPage/YBMiShuProvider/YBMiShuProvider.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBWorkTaiModule/YBZhuanShuYingYongPage/YBMiShuYiJiHeLvSiMainPage.dart';
import 'YBMiShuProvider/YBShuaXinShengYuChiShuEventBus.dart';
import 'YBMiShuSubPage/YBMiShuTongListSubPage.dart';
import 'YBMiShuSubPage/YBMiShuTongListYiHuoFeedStatusPage.dart';


enum mishuGongGongType {
  mishuGongGongTYpe_yijitong,
  mishuGongGongTYpe_lvsitong,
}


class YBMiShuListPage extends StatelessWidget {

  final mishuGongGongType type;

  const YBMiShuListPage({Key key, this.type}) : super(key: key);




  @override
  Widget build(BuildContext context) {

    String miType;

    if (type == mishuGongGongType.mishuGongGongTYpe_lvsitong) {
         miType = "xg_jinrilvsi";
    } else if (type == mishuGongGongType.mishuGongGongTYpe_yijitong) {
        miType = "xg_newyijiwang";
    }


    return Container(
      child: DefaultTabController(
          length: 3,
          child:Scaffold(
            appBar: AppBar(
                  elevation: 0,
                  title: Text(YBChineseText.workTaiShangJiKuTitle,style: YBTextStyle.TextStyle30313320Medium),
                  bottom: TabBar(
                      indicatorSize: TabBarIndicatorSize.label,
                      unselectedLabelColor: YBColor.color1B1C1F,
                      labelColor: YBColor.commonThemeColor,
                      indicatorColor: YBColor.commonThemeColor,
                      tabs: [
                        Tab(text: YBChineseText.workTaiGonggongShangJiTitle,),
                        Tab(text: YBChineseText.workTaiYouXuanShangJiTitle,),
                        Tab(text: YBChineseText.workTaiYiHuoShangJiTitle,),
                      ]
                  ),
            ),
            body:TabBarView(
              children: [
                Container(
                  child: Column(
                    children: [
                      Container(
                        child: ChangeNotifierProvider(create:(context) => YBGongGongShengYuNumberProvider()..getGongGongYouXuanDataList(miType),
                        child: Consumer<YBGongGongShengYuNumberProvider>(builder:(context,shengYuCiShu,child){

                          shuaXinShengYuchiShuEventBus.on<YBShuaXinShengYuChiShuEventBus>().listen((event) {
                              shengYuCiShu.getGongGongYouXuanDataList(miType);
                          });


                          return Container(
                              alignment: Alignment.centerLeft,
                              height: YBTextStyle.adapterSize26,
                              color: YBColor.common2D69E0,
                              child: Padding(
                                padding: EdgeInsets.only(left: YBTextStyle.adapterSize20),
                                child: Text( '${YBChineseText.workTaiGongGongEventDayGetTitle}${shengYuCiShu.todayShengYuNumberStr}条',
                                  style:YBTextStyle.TextStyleA9AEB813,
                                ),
                              ),
                            );
                          }),
                        ),
                      ),
                      Expanded(
                        child:ChangeNotifierProvider(
                             create: (context) => YBYiJiTongLvSiTongProvider()..getYiJiDataList(1, miType),
                             child: Consumer<YBYiJiTongLvSiTongProvider>(
                                 builder: (context,yiJiDataList,child){

                                   return SmartRefresher(
                                     controller:yiJiDataList.easyRefreshController,
                                     onRefresh: () async {
                                       yiJiDataList.refreshData(miType);
                                     },
                                     onLoading: () async {
                                       yiJiDataList.loadData(miType);
                                     },
                                     enablePullUp: true,
                                     enablePullDown: true,
                                     child: CustomScrollView(
                                       slivers: [
                                         SliverList(
                                           delegate: SliverChildBuilderDelegate((_,int index){
                                             YBWorkTaiBaseYiJiModel yiJiModel = yiJiDataList.yiJiModelList[index];
                                             return Container(
                                               child: InkWell(
                                                 child: YBMiShuTongListSubPage(timeStr: yiJiModel.latestTime,addressStr:'${yiJiModel.provinceName}-${yiJiModel.cityName}',contentStr: yiJiModel.requestServiceDesc,sysCode: miType,requestCode: yiJiModel.requestCode,),
                                                 onTap: () async {
                                                   YBApplication.router.navigateTo(context, '/workTaiPage/workTaiMiShuTongPage/workTaiMiShuShangJikuPage/workTaiMiShuShangjikuListDetailPage?syscode=$miType&requestcode=${yiJiModel.requestCode}');
                                                 },
                                               ),
                                             );
                                           },
                                             childCount: yiJiDataList.yiJiModelList.length,
                                           ),
                                         ),
                                       ],
                                     ),
                                   );
                                 }
                             ),
                        ),
                      ),
                    ],
                  ),
                ),
                Container(
                  child: Column(
                    children: [
                      Container(
                        alignment: Alignment.centerLeft,
                        height: YBTextStyle.adapterSize26,
                        color: YBColor.common2D69E0,
                        child: Padding(
                          padding: EdgeInsets.only(left: YBTextStyle.adapterSize20),
                          child: Text(YBChineseText.workTaiYouXuanGetHuoTitle,
                            style:YBTextStyle.TextStyleA9AEB813,
                          ),
                        ),
                      ),
                      Expanded(
                        child: ChangeNotifierProvider(
                            create:(context) => YBYiJiLvSiBaseYouXuanShangJi()..getYouXuanDataList(1, miType, "2"),
                            child: Consumer<YBYiJiLvSiBaseYouXuanShangJi>(
                                builder: (context,youXuanList,child){

                                  return SmartRefresher(
                                    controller:youXuanList.easyRefreshController,
                                    onLoading: () async {
                                      youXuanList.loadData(miType, "2");
                                    },
                                    onRefresh: () async {
                                      youXuanList.refreshData(miType, "2");
                                    },
                                    enablePullDown: true,
                                    enablePullUp: true,
                                    child: CustomScrollView(
                                      slivers: [
                                        SliverList(
                                          delegate: SliverChildBuilderDelegate((_,int index){
                                            YBWorkTaiBaseYiJiModel yijiModel = youXuanList.youXuanModelList[index];
                                            ///workTaiPage/workTaiLvSiTongPage/workTaiMiShuYouxuanDetailPage
                                            return Container(
                                              child: InkWell(
                                                child: YBMiShuTongListSubPage(timeStr:yijiModel.createTime,addressStr: "${yijiModel.request.provinceName}-${yijiModel.request.cityName}",contentStr:yijiModel.request.requestServiceDesc,sysCode: miType,requestCode: yijiModel.requestCode,),
                                                onTap: () async {
                                                  YBApplication.router.navigateTo(context, '/workTaiPage/workTaiLvSiTongPage/workTaiMiShuYouxuanDetailPage?syscode=$miType&requestcode=${yijiModel.requestCode}');
                                                },
                                              ),
                                            );
                                          },
                                            childCount: youXuanList.youXuanModelList.length,
                                          ),
                                        ),
                                      ],
                                    ),
                                  );

                                }
                            ),
                        ),
                      ),
                    ],
                  ),
                ),
                Container(
                  child: YBMiShuYiJiHeLvSiMainPage(miType: miType,),
                ),
              ],
            ),
          ),
      ),
    );
  }
}
